import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:opene/app_theme.dart';
import 'package:opene/app_utils.dart';
import 'package:opene/ui/cms/cmsmodel.dart';

class CMSTallyedDetailDialog extends StatefulWidget {
  int type;
  CMSTally tally;
  CMSTallyedDetail tallyDetails;

  CMSTallyedDetailDialog({this.type, this.tally, this.tallyDetails});

  @override
  _CMSTallyedDetailDialogState createState() => _CMSTallyedDetailDialogState(type: type, tally: tally, tallyDetails: this.tallyDetails);
}

class _CMSTallyedDetailDialogState extends State<CMSTallyedDetailDialog> {
  int type;
  CMSTally tally;
  CMSTallyedDetail tallyDetails;

  _CMSTallyedDetailDialogState({this.type, this.tally, this.tallyDetails});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Detail(${tally.containerNo})", style: MyAppTheme.title),
            SizedBox(height: 16.0),
            Row(
              children: [
                Expanded(
                    flex: 3,
                    child: Text(
                      type == 0 ? "LPN Type(${tallyDetails.tallyedList == null ? "0" : tallyDetails.tallyedList.length})" : "LPN Type",
                      style: MyAppTheme.text,
                    )),
                Expanded(flex: 2, child: Text(type == 0 ? "Tallied(${tallyDetails.total == null ? "0" : '${tallyDetails.total}'})" : "Tallied", style: MyAppTheme.text)),
              ],
            ),
            Flexible(
              fit: FlexFit.loose,
              child: setListView(),
            ),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Close',
                        style: MyAppTheme.title,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    )),
                Visibility(
                  visible: type == 1 ? true : false,
                  child: Expanded(
                      flex: 1,
                      child: FlatButton(
                        child: Text(
                          'Confirm',
                          style: MyAppTheme.titlenearlyBlue16,
                        ),
                        onPressed: () {
                          Navigator.of(context).pop(true);
                        },
                      )),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  ListView setListView() {
    return ListView.builder(
      shrinkWrap: true,
      // physics: NeverScrollableScrollPhysics(),
      itemCount: tallyDetails.tallyedList == null ? 0 : tallyDetails.tallyedList.length,
      itemBuilder: (context, index) {
        CMSTallyDetail tallyDetail = tallyDetails.tallyedList[index];
        return Column(
          children: [
            Row(
              children: [
                Expanded(
                    flex: 3,
                    child: Text(
                      Utils.getStringisEmpty(tallyDetail.destination),
                      style: MyAppTheme.text,
                    )),
                Expanded(flex: 2, child: Text('${tallyDetail.num}', style: MyAppTheme.text)),
              ],
            ),
            Divider(),
          ],
        );
      },
    );
  }
}

class CMSOBLPNDetailDialog extends StatefulWidget {
  CMSOBLPN tally;
  List<CMSOBLPNDetails> tallyDetails;

  CMSOBLPNDetailDialog({this.tally, this.tallyDetails});

  @override
  _CMSOBLPNDetailDialogState createState() => _CMSOBLPNDetailDialogState(tally: tally, tallyDetails: this.tallyDetails);
}

class _CMSOBLPNDetailDialogState extends State<CMSOBLPNDetailDialog> {
  CMSOBLPN tally;
  List<CMSOBLPNDetails> tallyDetails;

  _CMSOBLPNDetailDialogState({this.tally, this.tallyDetails});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Dest: ${tally.destination}", style: MyAppTheme.title),
            SizedBox(height: 16.0),
            Row(
              children: [
                Expanded(
                    flex: 1,
                    child: Text(
                      tallyDetails == null ? "PalltetLPN(0)" : "PalltetLPN(${Utils.getStringisInteger(tallyDetails.length)})",
                      style: MyAppTheme.text,
                    )),
                Expanded(flex: 1, child: Text("Location", style: MyAppTheme.text)),
              ],
            ),
            Flexible(
              fit: FlexFit.loose,
              child: setListView(),
            ),

            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Close',
                        style: MyAppTheme.title,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    )),
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Confirm',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(true);
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }

  ListView setListView() {
    return ListView.builder(
      shrinkWrap: true,
      // physics: NeverScrollableScrollPhysics(),
      itemCount: tallyDetails == null ? 0 : tallyDetails.length,
      itemBuilder: (context, index) {
        CMSOBLPNDetails tallyDetail = tallyDetails[index];
        return Column(
          children: [
            Visibility(
                visible: index==0?true:false,
                child: SizedBox(height: 5,)),
            Row(
              children: [
                Expanded(
                    flex: 1,
                    child: Text(
                      Utils.getStringisEmpty(tallyDetail.palletLpn),
                      style: TextStyle(color: Utils.getIntegerisEmpty(tallyDetail.isPick) == 0 ? MyAppTheme.red : MyAppTheme.color_666666, fontSize: 12.0),
                    )),
                Expanded(
                    flex: 1,
                    child: Text(
                      Utils.getStringisEmpty(tallyDetail.location),
                      style: TextStyle(color: Utils.getIntegerisEmpty(tallyDetail.isPick) == 0 ? MyAppTheme.red : MyAppTheme.color_666666, fontSize: 12.0),
                    )),
              ],
            ),
            Divider(),
          ],
        );
      },
    );
  }
}
